package com.nuyoah.service.impl;

import com.nuyoah.common.dto.TeachingPlanDto;
import com.nuyoah.entity.Course;
import com.nuyoah.entity.TeachingPlan;
import com.nuyoah.mapper.TeachingPlanMapper;
import com.nuyoah.service.CourseService;
import com.nuyoah.service.TeachingPlanService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 存储每门课程具体的教学计划，与课程和教师关联 服务实现类
 * </p>
 *
 * @author xyx
 * @since 2024-06-25
 */
@Service
public class TeachingPlanServiceImpl extends ServiceImpl<TeachingPlanMapper, TeachingPlan> implements TeachingPlanService {

    @Autowired
    private CourseService courseService;

    @Override
    public List<TeachingPlan> getTeachingPlanByTeacherId(Integer teacherId) {
        return this.baseMapper.getTeachingPlanByTeacherId(teacherId);
    }

    @Override
    public List<TeachingPlanDto> getTeachingPlanDtoList(List<TeachingPlan> list) {
        List<TeachingPlanDto> planDtoList = new ArrayList<>();
        for (TeachingPlan plan : list) {
            TeachingPlanDto planDto = new TeachingPlanDto();

            BeanUtils.copyProperties(plan, planDto);
            Course course = courseService.getById(plan.getCourseId());
            if(course!= null){
                planDto.setCourseName(course.getCourseName());
            }else{
                planDto.setCourseName("未知");
            }
            planDtoList.add(planDto);
        }
        return planDtoList;
    }
}
